//
//  TUserInfoDAL.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/11/8.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "TUserInfoDAL.h"
#import "CSFMDBTool.h"

@implementation TUserInfoDAL


+ (TUserInfoModel *)loadUserModelWithDict:(NSDictionary *)dict {
    TUserInfoModel * model = [[TUserInfoModel alloc] init];
    model.uId = [dict[@"uId"] intValue];
    model.uUserNo = dict[@"uUserNo"];
    model.uUserName = dict[@"uUserName"];
    model.uType = [dict[@"uType"] intValue];
    model.uPhone = dict[@"uPhone"];
    model.uAddr = dict[@"uAddr"];
    model.uWarehouseNo = dict[@"uWarehouseNo"];
    model.uCreateTime = dict[@"uCreateTime"];
    model.uRemark = dict[@"uRemark"];
    
    return model;
}

+ (NSArray<TUserInfoModel *> *)loadUserListWithSql:(NSString *)sql {
    NSMutableArray<TUserInfoModel *> * mArr = [NSMutableArray<TUserInfoModel *> array];
    NSArray<NSDictionary *> * arr = [[CSFMDBTool SharedFmdbTool] loadDataWithSql:sql];
    for (NSDictionary *dict in arr) {
        TUserInfoModel * model = [self loadUserModelWithDict:dict];
        [mArr addObject:model];
    }
    return mArr.copy;
}

+ (TUserInfoModel *)loadUserModelWithSql:(NSString *)sql {
    NSArray<NSDictionary *> * arr = [[CSFMDBTool SharedFmdbTool] loadDataWithSql:sql];
    if (arr.count == 0) {
        return nil;
    }
    TUserInfoModel * model = [self loadUserModelWithDict:arr[0]];
    return model;
}

+ (NSArray<TUserInfoModel *> *)loadUserListWithBusinessNo:(NSString *)businessNo {
    NSString * sql = [NSString stringWithFormat:@"select * from tUserInfo where uUserNo='%@'; ", businessNo];
    return [self loadUserListWithSql:sql];
}

+ (TUserInfoModel *)loadUserModelWithBusinessNo:(NSString *)businessNo {
    NSString *sql = [NSString stringWithFormat:@"select * from tUserInfo where uUserNo='%@'; ", businessNo];
    return [self loadUserModelWithSql:sql];
}

+ (TUserInfoModel *)loadUserModelWithUserNo:(NSString *)userNo {
    NSString *sql = [NSString stringWithFormat:@"select * from tUserInfo where uUserNo='%@'; ", userNo];
    return [self loadUserModelWithSql:sql];
}


@end
